package njiandan.mvc.converter;

public interface Converter<T> {

	/**
	 * Convert a not-null String to specified object.
	 */
	T convert(String s);

}

class BooleanConverter implements Converter<Boolean> {

	public Boolean convert(String s) {
		return Boolean.parseBoolean(s);
	}

}

class ShortConverter implements Converter<Short> {

	public Short convert(String s) {
		return Short.parseShort(s);
	}

}

class LongConverter implements Converter<Long> {

	public Long convert(String s) {
		return Long.parseLong(s);
	}

}

class IntegerConverter implements Converter<Integer> {

	public Integer convert(String s) {
		return Integer.parseInt(s);
	}

}

class FloatConverter implements Converter<Float> {

	public Float convert(String s) {
		return Float.parseFloat(s);
	}

}

class DoubleConverter implements Converter<Double> {

	public Double convert(String s) {
		return Double.parseDouble(s);
	}

}

class ByteConverter implements Converter<Byte> {

	public Byte convert(String s) {
		return Byte.parseByte(s);
	}

}

class CharacterConverter implements Converter<Character> {

	public Character convert(String s) {
		if (s.length() == 0)
			throw new IllegalArgumentException(
					"Cannot convert empty string to char.");
		return s.charAt(0);
	}

}
